<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class XcDevice extends Model
{
    protected $table = 'xc_device';
    protected $guarded = ['id'];

    

    public static function GetFactory($id = '')
    {
        //洗车机品牌列表，目前只有一种
        $factory_arra = [
                            ['id' => 'yumai','name' => '宇脉洗车机', 'ci' => 'YM'],
                        ];
        if (!empty($id)){
            foreach ($factory_arra as $k => $v) {
                if ($id == $v['id']){
                    return $v;
                }
            }
        }
        return $factory_arra;
    }

    public function factory()
    {
        return $this->belongsTo('App\Models\XcFactory','factory_id','id');
    }

    public function site()
    {
        return $this->hasOne('App\Models\XcSite','id', 'site_id');
    }

    //生成设备的外部编号
    public static function GetOpenSN($length = 8)
    {
    	return substr(md5(time()), 0, $length);
    }
}
